<?php

class Invoice extends My_Controller
{
    public function all()
    {   if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
         $this->load->library('pagination');
        $config['base_url']   = base_url(). "invoice/all";
        $config['total_rows'] = $this->m_invoice->count_data_all();
        $config['per_page']   = 15;
        $config['use_page_numbers']=TRUE;
        $config['uri_segment'] = 3;
         $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&lt;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="current"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
         
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
         
        $config['first_link'] = '&lt;&lt;';
        $config['last_link'] = '&gt;&gt;';
        $this->pagination->initialize($config); 
        $tranghienhanh = $this->uri->segment(3)?$this->uri->segment(3):1;
        $start = ($tranghienhanh-1)*$config['per_page'];
        $data['pagination'] = $this->pagination->create_links();
        $data['info'] = $this->m_invoice->invoice_phan_trang_all($config['per_page'],$start);
        $this->load->view('invoice/invoice_all',$data);
         } else redirect('account/login_admin');
    }
     public function chua_xu_ly()
    {
        if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
         $this->load->library('pagination');
        $config['base_url']   = base_url(). "invoice/chua_xu_ly";
        $config['total_rows'] = $this->m_invoice->count_data_chua_xu_ly();
        $config['per_page']   = 15;
        $config['use_page_numbers']=TRUE;
        $config['uri_segment'] = 3;
         $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&lt;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="current"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
         
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
         
        $config['first_link'] = '&lt;&lt;';
        $config['last_link'] = '&gt;&gt;';
        $this->pagination->initialize($config); 
        $tranghienhanh = $this->uri->segment(3)?$this->uri->segment(3):1;
        $start = ($tranghienhanh-1)*$config['per_page'];
        $data['pagination'] = $this->pagination->create_links();
        $data['info'] = $this->m_invoice->invoice_phan_trang_chua_xu_ly($config['per_page'],$start);
        $this->load->view('invoice/invoice_chuaxuly',$data);
         } else redirect('account/login_admin');
    }
     public function da_xu_ly()
    {
        if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
         $this->load->library('pagination');
        $config['base_url']   = base_url(). "invoice/da_xu_ly";
        $config['total_rows'] = $this->m_invoice->count_data_da_xu_ly();
        $config['per_page']   = 15;
        $config['use_page_numbers']=TRUE;
        $config['uri_segment'] = 3;
         $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&lt;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="current"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
         
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
         
        $config['first_link'] = '&lt;&lt;';
        $config['last_link'] = '&gt;&gt;';
        $this->pagination->initialize($config); 
        $tranghienhanh = $this->uri->segment(3)?$this->uri->segment(3):1;
        $start = ($tranghienhanh-1)*$config['per_page'];
        $data['pagination'] = $this->pagination->create_links();
        $data['info'] = $this->m_invoice->invoice_phan_trang_da_xu_ly($config['per_page'],$start);
        $this->load->view('invoice/invoice_daxuly',$data);
         } else redirect('account/login_admin');
    }
    public function chi_tiet()
    {
         if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
        $id = $this->uri->segment(3);
        $invoice = $this->m_invoice->get_invoice_by_id($id);
        $detail = $this->m_payment->load_invoice_detail_by_invoiceid($id);
        $user = $this->m_account->get_account_by_id($invoice[0]->ACCOUNT_ID);
        $data['user'] = $user;
        $data['invoice'] = $invoice;
        $data['detail'] = $detail;
        $this->load->view('invoice/invoice_detail',$data);
        } else redirect('account/login_admin');
    }
    public function update_don_hang()
    {
        if($this->session->userdata('role') == 1 || $this->session->userdata('role') == 3 ) {
       /* $id = $this->uri->segment(3);
        date_default_timezone_set('Asia/Ho_Chi_Minh');
        $date = getdate();
        $ngaycapnhat = $date['year'].'-'.$date['mon'].'-'.$date['mday'];        
        $thongtin = $this->input->post('decrip');
        var_dump($id); var_dump($thongtin); exit;*/
        if($this->input->post('xuly')!= '')
            {
                $id = $this->input->post('invoiceid');
                date_default_timezone_set('Asia/Ho_Chi_Minh');
                $date = getdate();
                $ngaycapnhat = $date['year'].'-'.$date['mon'].'-'.$date['mday'].' '.$date['hours'].':'.$date['minutes'].':'.$date['seconds'];
                $thongtin = $this->input->post('decrip');
                $status = $this->input->post('status');
                $luu = $this->m_invoice->update_don_hang($id,$ngaycapnhat,$status,$this->session->userdata('accountid'),$thongtin);
                redirect('invoice/chi_tiet/'.$id);
            }

              } else redirect('account/login_admin');
    }
}
?>